using System;
using System.Collections.Generic;
using Orchard;
//using Bootstrap.Features;
using Bootstrap.Services;

namespace Bootstrap.Models {
    public interface IBootstrapFeature : IDependency {
        void Describe(FeatureDescriptionContext context);
    }

    public class FeatureDescriptor {

        protected readonly List<string> _requiredFeatures = new List<string>();

        public string Name { get; set; }
        public string FeatureType { get; set; }
        public string DisplayName { get; set; }
        public string Description { get; set; }
        public IBootstrapFeatureCategory Category { get; set; }
        public int DisplayPriority { get; set; }
        public Func<IBootstrapSettingsService, string[]> Action { get; set; }
        
        public IEnumerable<string> RequiredFeatures { get { return _requiredFeatures; } } 

        public FeatureDescriptor IsType(string type) {
            FeatureType = type;
            return this;
        }

        public FeatureDescriptor WithDisplayName(string displayName) {
            DisplayName = displayName;
            return this;
        }

        public FeatureDescriptor WithDescription(string description) {
            Description = description;
            return this;
        }

        public FeatureDescriptor WithCategory(IBootstrapFeatureCategory category, int displayPriority) {
            Category = category;
            DisplayPriority = displayPriority;
            return this;
        }

        public FeatureDescriptor WithAction(Func<IBootstrapSettingsService, string[]> action) {
            Action = action;
            return this;
        }

        public FeatureDescriptor Requires(string name) {
            if (!_requiredFeatures.Contains(name))
                _requiredFeatures.Add(name);
            return this;
        }

        
    }

    public class FeatureDescriptionContext {


        public Dictionary<string, Func<FeatureDescriptor, FeatureDescriptor>> Features { get; private set; }

        public FeatureDescriptionContext() {
            Features = new Dictionary<string, Func<FeatureDescriptor, FeatureDescriptor>>();
            
        }
        public FeatureDescriptionContext Describe(string name, Func<FeatureDescriptor, FeatureDescriptor> descriptor)
        {
            Features.Add(name, descriptor);
            return this;
        }
    }}